package com.moi.summer;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;

/**
 * Created by moi on 2015/2/25.
 */
public class DownloadFragment extends Fragment {

    private TextView download;
    private ImageView imageView;
    private ImageLoader.ImageListener listener;
    private ImageLoader imageLoader;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.download, container, false);

        RequestQueue mQueue = Volley.newRequestQueue(view.getContext());

        imageLoader = new ImageLoader(mQueue, new ImageLoader.ImageCache() {
            @Override
            public Bitmap getBitmap(String s) {
                return null;
            }

            @Override
            public void putBitmap(String s, Bitmap bitmap) {

            }
        });


        imageView = (ImageView) view.findViewById(R.id.iv_download);

        listener = ImageLoader.getImageListener(imageView, R.drawable.loading, R.drawable.error);
        download = (TextView) view.findViewById(R.id.tv_download);
        download.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageLoader.get("http://a2.qpic.cn/psb?/d236dc96-be3d-47aa-8e07-231533d6f9da/3B07iTxX7LbWZoDlUlj.wKStIlUfYN6SaR.W1zpl3T4!/b/dAQAAAAAAAAA&bo=HAJLAhwCSwIDCSw!&rf=viewer_4",
                        listener);

            }
        });
        imageView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
                builder.setTitle("噢肉！")//设置标题
                        .setMessage("扫不了？喂猫？\n颜色不对嘛！请自行调对比度！、\n给您带来的不便，敬请原谅！:)")//设置提示消息
                        .setNeutralButton("好吧",new DialogInterface.OnClickListener() {//中间按钮
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //do something
                            }
                        })
                        .setCancelable(false)//设置按返回键是否响应返回，这是是不响应
                        .show();//显示
                return false;
            }
        });
        return view;

    }
}
